#include "net.hpp"
#include "message.hpp"
#include <muduo/base/Logging.h>

void onMessage(const RPC::BaseConnection::Ptr& conn, RPC::BaseMessage::Ptr& msg)
{
    std::string body = msg->serialize();
    std::cout << body << std::endl;
}


int main()
{
    muduo::Logger::setLogLevel(muduo::Logger::FATAL);
    RPC::BaseClient::Ptr client = RPC::ClientFactory::create("127.0.0.1", 9090);
    client->SetMessageCallback(onMessage);
    client->connect();
    auto rpc_req = RPC::MessageFactory::create<RPC::RpcRequest>();
    rpc_req->setId("11111");
    rpc_req->setType(RPC::MType::REQ_RPC);
    rpc_req->setMethod("add");
    Json::Value val;
    val["num1"] = 11;
    val["num2"] = 22;
    rpc_req->setParam(val);
    client->send(rpc_req);
    sleep(10);
    client->shutdown();
    return 0;
}